<?php
class N_View_Abstract
{
	/**
	 * 管理view类实例
	 *
	 * @var N_View_Abstract object
	 */
	protected $tpl = null;

	
	public function __construct()
	{
		$templateEnginerClassName = N::getIni('TEMPLATE_ENGINER_CLASS');
		$templateEnginerPath = N::getIni('TEMPLATE_ENGINER_PATH');
		if (is_file($templateEnginerPath))
		{
			include_once($templateEnginerPath);
		}
		else 
		{
			str_replace('\\', '/', $templateEnginerPath);
			rtrim($templateEnginerPath, '/');
			$templateEnginerPath .= '/';
			N::import($templateEnginerPath);
			N::loadClass($templateEnginerClassName);
		}
		$this->_tpl = N::getSingleton($templateEnginerClassName);
		if (is_null($this->_tpl))
		{
			throw new Exception("不能实例化类: $templateEnginerClassName!");
		}
		$templateConfig = N::getIni('TEMPLATE_CONFIG');
		foreach ($templateConfig as $key=>$value)
		{
			$this->_tpl->$key = $value;	
		}
	}
	
	/**
	 * 返回模板引擎类实例
	 *
	 * @return Object
	 */
	public function getTpl()
	{
		return $this->_tpl;
	}
	
	/**
	 * 用来调用模板类的方法
	 *
	 * @param string $func
	 * @param array $args
	 */
	public function __call($func, $args)
	{
		call_user_func_array(array($this->_tpl, $func), $args);
	}
}